import { Component } from '@angular/core';

import { NavController, LoadingController, NavParams} from 'ionic-angular';
import {SearchService} from "../../services/search.service";

@Component({
  selector: 'page-xwlist',
  templateUrl: 'xinwen-list.html',
  providers: [SearchService],
})
export class XinwenList {

  public pdata:number;
  public dataset:any=[];

  constructor(
    public navCtrl: NavController,
    public loadingCtrl: LoadingController,
    public navParams: NavParams,
    public service: SearchService,
  ){
    this.pdata=navParams.get('p').id;
    this.getXinwenList(this.pdata);
  }

  getXinwenList(id:number){
    this.showLoading('加载中');
    this.service.getXwList(id).subscribe(
      data => {
        this.dataset.id=data.id;
        this.dataset.title=data.title;
        this.dataset.from=data.from;
        this.dataset.time = data.time;
        this.dataset.content=data.content;
        document.getElementById("inbox").innerHTML=data.content;

        setInterval(aa => this.hideLoading(),300)
      },
      error => {
        console.log('新闻子页面-失败');
        this.hideLoading();
      }
    )};


  public loading;

  showLoading(message) {
    this.loading = this.loadingCtrl.create({
      content: message,
      duration: 2000
    });
    this.loading.present();
  }

  hideLoading() {
    if (this.loading != null) {
      this.loading.dismissAll();
    }
  }

  showToast(message: string) {
    let toast = this.loadingCtrl.create({
      duration: 1000,
    });
    toast.present();
  }


}
/**
 * Created by lanejishu on 2017/2/13.
 */
